package com.hzqy.web.ac.system;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.ExcelUtil;
import com.hzqy.commons.utils.ExcelUtil.MyEntry;
import com.hzqy.service.system.SysProcessLogsServiceBeen;
import com.hzqy.service.system.SysVoProcessServiceBeen;
import com.hzqy.web.vo.SysProcessLogsVo;
import com.hzqy.web.vo.content.CmContentLedgerVo;
@Controller
@RequestMapping("/")
public class SysProcessLogsServiceAction{
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private SysProcessLogsServiceBeen sysProcessLogsServiceBeen;
	@Resource
	private SysVoProcessServiceBeen voProcessServiceBean;
	
	@RequestMapping("/system/select_sys_processlogs_list")
	@ResponseBody
	public Object sysProcessLogsList(SysProcessLogsVo sysProcessLogsVo, HttpSession session, int page, int rows){
		Map<String,Object> SystemListMap = new HashMap<String, Object>();
		SystemListMap =  sysProcessLogsServiceBeen.selectProcessLogsVoList(sysProcessLogsVo,page, rows);
		return SystemListMap;
	}
	
	@RequestMapping("/statistics/selectContentLedgerList")
	@ResponseBody
	public Object selectContentLedgerList(CmContentLedgerVo cmContentLedgerVo, int page, int rows){
		Map<String, Object> map=sysProcessLogsServiceBeen.selectContentLedgerList(cmContentLedgerVo,page,rows);
		return map;
	}
	@RequestMapping("/system/excel_list")
	public void excelList(SysProcessLogsVo sysProcessLogsVo,HttpServletResponse response, int page, int rows) throws IOException{
		Map<String,Object> SystemListMap = new HashMap<String, Object>();
		SystemListMap =  sysProcessLogsServiceBeen.selectProcessLogsVoList(sysProcessLogsVo,  page,  rows);
		List<SysProcessLogsVo> list=new ArrayList<SysProcessLogsVo>();
		list = (List<SysProcessLogsVo>)SystemListMap.get("rows");
		voProcessServiceBean.voProcess(list);
		List<MyEntry<String, String>> excelCpHeader=new ArrayList<MyEntry<String, String>>();
		excelCpHeader.add(new MyEntry<String,String>("f_spl_id","ID"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_name","操作名称"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_url","操作路径"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_requestip","操作请求ip"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_operateid","操作页面执行id"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_before","操作前数据"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_after","操作后数据"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_userid","操作人ID"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_username","操作人账号"));
		excelCpHeader.add(new MyEntry<String,String>("f_spl_cdate","创建时间"));
		boolean flag=ExcelUtil.generateExcel(list, excelCpHeader, response);
	}

	@RequestMapping("/statistics/contentLedger_excel_list")
	public void contentLedgerExcelList(CmContentLedgerVo cmContentLedgerVo,HttpServletResponse response, int page, int rows) throws IOException{
		Map<String,Object> SystemListMap = new HashMap<String, Object>();
		SystemListMap =  sysProcessLogsServiceBeen.selectContentLedgerList(cmContentLedgerVo,  page,  rows);
		List<CmContentLedgerVo> list=new ArrayList<CmContentLedgerVo>();
		list = (List<CmContentLedgerVo>)SystemListMap.get("rows");
		for(int i=0;i<list.size();i++){
			String  str = "未知";
			if(list.get(i).getF_ccl_type()==1){
				str = "新增";
			}else if(list.get(i).getF_ccl_type()==2){
				str = "修改";
			}else if(list.get(i).getF_ccl_type()==3){
				str = "市审核";
			}else if(list.get(i).getF_ccl_type()==4){
				str = "省审核";
			}else if(list.get(i).getF_ccl_type()==5){
				str = "牌照审核";
			}else if(list.get(i).getF_ccl_type()==6){
				str = "删除";
			}
			list.get(i).setF_ccl_type_name(str);
		} 
		
		voProcessServiceBean.voProcess(list);
		List<MyEntry<String, String>> excelCpHeader=new ArrayList<MyEntry<String, String>>();
		excelCpHeader.add(new MyEntry<String,String>("f_ccl_id","ID"));
		excelCpHeader.add(new MyEntry<String,String>("f_ccl_user","操作用户名称"));
		excelCpHeader.add(new MyEntry<String,String>("f_ccl_contentName","操作节目名称"));
		excelCpHeader.add(new MyEntry<String,String>("f_ccl_ip","ip"));
		excelCpHeader.add(new MyEntry<String,String>("f_ccl_mac","mac"));
		
		
		excelCpHeader.add(new MyEntry<String,String>("f_ccl_type_name","操作类型"));
		excelCpHeader.add(new MyEntry<String,String>("f_ccl_cdate","创建时间"));
		boolean flag=ExcelUtil.generateExcel(list, excelCpHeader, response);
	}
}
